package com.liu;

import lombok.Data;

import java.util.Objects;

/**
 * @author liumiao
 * @create 2021-10-23-19:05
 */
@Data
public class Person {
    private String name;
    private int age;

/*    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }*/

    @Override
    public boolean equals(Object object) {
        if (this == object) return true;
        if (!(object instanceof Person)) return false;
        Person person = (Person) object;
        return getAge() == person.getAge() &&
                Objects.equals(getName(), person.getName());
    }

    @Override
    public int hashCode() {
        int result =getName() !=null ? getName().hashCode() : 0;
        result = 31 * result + age;
        return result;
    }

    public static void main(String[] args) {
        Person liu = new Person();
        Person miao = new Person();
        liu.setName("liu");
        miao.setName("liu");
        System.out.println(liu.hashCode());
        System.out.println(miao.hashCode());
        System.out.println(liu.hashCode()==miao.hashCode());
    }
}
